<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- 引入 Bootstrap -->
<link href="../../style/bootstrap-4.6.0-dist/css/bootstrap.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style>
    h1{
        text-align: center;
    }
    #checkAll, .check {
        width: 20px;
        height: 20px;
    }
    #add_btn {
        background: #009688;
        height: 43px;
        width: 82px;
        border-radius: 10px;
        cursor: pointer;
        color: #FBFBFB;
        margin-right: 10px;
        margin-left: 420px;
    }
    #del_btn {
        background: #e4606d;
        height: 43px;
        width: 82px;
        border-radius: 10px;
        cursor: pointer;
        color: #FBFBFB;
        margin-top: 10px;
        margin-left: 20px;
    }
    /*搜索框1*/
    .bar1 {
        width: 455px;
        height: 40px;
        display: inline-block;
        margin-left: 20px;
    }

    #CompanyName,#Phone {
        width: 285px;
        height: 40px;
        color: #0f6674;
        font-weight: bold;
        border-radius: 7px;
    }

    #sous_btn {
        display: inline-block;
        width: 40px;
        height: 40px;
        margin-right: 56px;
    }

    #sous_form {
        width: 900px;
    }

    .bar1 input {
        border: 2px solid #7BA7AB;
        border-radius: 5px;
        background: #F9F0DA;
        color: #9E9C9C;
        outline:none;
    }

    .bar1 button {
        top: 0;
        right: 0;
        background: #7BA7AB;
        border-radius: 0 5px 5px 0;
    }

    .bar1 button:before {
        content: "\f002";
        font-family: FontAwesome;
        font-size: 16px;
        color: #F9F0DA;
    }
    label {
        font-weight: bold;
        font-size: 20px;
    }
    #tr_text td{
        font-weight: bold;
    }
    #customer-tab{
        margin-top: 15px;
        background: #f8f9fa;
    }
    #upd_btn {
        background: orange;
        height: 38px;
        width: 72px;
        border-radius: 10px;
        cursor: pointer;
        color: #FBFBFB;
    }
</style>
<body>
    <div id="customerContent">
        <div class="container-fluid">
            <!--   row   一行  -->
            <div class="row">
                <div class="col-xl-12" id="top_div">
                    <div class="search bar1">
                        <form id="sous_form">
                            <label>公司名称：</label>
                            <input id="CompanyName" name="CompanyName" type="text" placeholder="按公司名称搜索...">
                            <label>联系方式：</label>
                            <input id="Phone" name="Phone" type="text" placeholder="按联系方式搜索...">
                            <button id="sous_btn" type="button" @click="search"></button>
                        </form>
                    </div>
                    <button type="button" id="add_btn" @click="add">
                        添加
                    </button>
                    <button type="button" id="del_btn" @click="del">删除</button>
                </div>
            </div>
        </div>
        <table id="customer-tab" class="table table-hover">
            <tr id="tr_text">
                <td><input type="checkbox" id="checkAll" @click="allCheck"></td>
                <td>客户ID</td>
                <td>客户司机编号</td>
                <td>公司名称</td>
                <td>公司地址</td>
                <td>信用度</td>
                <td>联系方式</td>
            </tr>
            <!--  page.list  page类的list  -->
            <tr v-for="customer in page.list" id="tr_text2">
                <td><input @click="isCheckAll" type="checkbox" :value="customer.customerNo" class="check"></td>
                <td>{{customer.customerNo}}</td>
                <td>{{customer.customerDriverNo}}</td>
                <td>{{customer.companyName}}</td>
                <td>{{customer.companyAddress}}</td>
                <td>{{customer.companyCredit==1?'良好':'差'}}</td>
                <td ><input type="text" style="border:none;background-color:transparent;"maxlength="11" minlength="11"
                            v-model="customer.phone"></td>
                <td>
                    <button id="upd_btn" type="button" @click="updCustomer(customer)">修改</button>
                </td>
            </tr>

        </table>
        <!--无序列表 翻页-->
        <ul class="pagination">
            <li class="page-item"><a class="page-link" href="javascript:void(0);" @click="toPage(1)">首页</a></li>
            <li class="page-item"><a class="page-link" href="javascript:void(0);" v-if="page.pageNow>1"
                                     @click="toPage(page.pageNow-1)">{{page.pageNow-1}}</a></li>
            <li class="page-item active"><a class="page-link" href="javascript:void(0);">{{page.pageNow}}</a></li>
            <li class="page-item"><a class="page-link" href="javascript:void(0);" v-if="page.pageNow<page.pageTotal"
                                     @click="toPage(page.pageNow+1)">{{page.pageNow+1}}</a></li>
            <li class="page-item"><a class="page-link" href="javascript:void(0);" @click="toPage(page.pageTotal)">尾页</a>
            </li>
        </ul>
    </div>


    <script src="../../style/jquery-3.3.1.js"></script>
    <script src="../../style/bootstrap-4.6.0-dist/js/bootstrap.js"></script>
    <script src="../../style/vue.js"></script>
    <script src="../../my1.1.js"></script>
    <script>

        $(function () {
            let page = selCustomerTable(1,"","");
            let app = new Vue({
                el: '#customerContent',
                data: {
                    page: page
                },
                methods: {
                    updCustomer: function (customer) {
                        //修改
                        $.ajax({
                            type: "post",
                            url: "../../Customer/updCustomer",
                            dataType: "json",
                            data: customer,
                            success: function () {
                                location.href='customer_list.html';
                            }
                        });
                    },
                    allCheck: function () {
                        eventHub.$emit('allCheck', null);
                    },
                    isCheckAll: function () {
                        eventHub.$emit('isCheckAll', null);
                    },
                    toPage: function (pageNow) {//当前页
                        let CompanyName = $("#CompanyName").val();
                        let Phone = $("#Phone").val();
                        this.page = selCustomerTable(pageNow,CompanyName,Phone);
                    },
                    search: function () {   //在点击事件里边调用
                        //点击搜索按钮，获取搜索内容，进行查询
                        let CompanyName = $("#CompanyName").val();
                        let Phone = $("#Phone").val();
                        this.page = selCustomerTable(1,CompanyName,Phone);
                    },
                    add:function (){
                        location.href='customer_add.html';
                    },
                    del: function () {
                        let ids = "";
                        // 获取复选框中的值 id值 使用类选择器each()遍历方法
                        $(".check").each(function () {
                            // 对所有符合该选择器的元素进行操作。this 复选框.value
                            // 判断该复选框是否选中
                            if (this.checked) {
                                ids += this.value + ",";
                            }

                        })
                        // ajax把拼接的id传入到后台
                        $.ajax({
                            type: "post",
                            url: "../../Customer/delCustomerAll",
                            data: {ids: ids},
                            dataType: "json",
                            success: function (data) {
                                alert(data.message);
                                location.href="customer_list.html";
                            }
                        })
                    }
                }
            })
        })
        function selCustomerTable(pageNow,CompanyName,Phone) {
            let page;//声明，然后在上边调用
            $.ajax({
                type: "post",
                data: {pageNow: pageNow,CompanyName:CompanyName,Phone:Phone},
                url: "../../Customer/selCustomerTable",
                async: false,
                dataType: "json",
                success: function (json) {
                    page = json; //把json对象赋值给data,然后返回
                }
            })
            return page;
        }
    </script>

</body>
</html>